<?php
/**
 * Created by PhpStorm.
 * User: l-ht
 * Date: 2018/11/12
 * Time: 10:28
 */

namespace app\admin\controller;


use app\admin\model\Admin;
use app\index\controller\Base;
use think\Request;

class Login extends Base
{

    public function login()
    {
        return view('login');
    }

    public function doLogin(Request $request)
    {
        $params = $request->param();

        $user = Admin::where('username',$params['username'])->find();

        if ($user) {
            if ($user['password'] == MD5($params['password'])) {
                unset($user['password']);
                cookie('user',json_encode($user));
                return $this->_toSuccess(['msg' => '登录成功']);
            }else{
                return $this->_toError(['msg' => '密码错误']);
            }
        }else{
            return $this->_toError(['msg' => '账户名不存在']);
        }


    }

    public function logout()
    {
        cookie('user',null);
        return $this->redirect('login');
    }

}